import {defineStore} from 'pinia'
//定义一个产品列表的仓库
export const useProductsStore = defineStore({
    id:'products',//仓库的ID，唯一的 
    state:()=>({  //定义仓库的状态对象
        products:[]
    }),
    actions:{
        async fetchProducts(){
            this.products= await queryProducts();
        }
    }
});

async function queryProducts(){
  return [
    {id:1,name:'apple',price:300,stock:3},
    {id:2,name:'huawei',price:200,stock:3},
    {id:3,name:'xiaomi',price:100,stock:3}
  ]
}